﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GuidingRobot;
using OperateWebcam;
using System.IO.Ports;

namespace my_GuidingRobot
{
    public partial class GuidingRobotForm : Form
    {
        private IOperateWebcam ow_path; // 路径信息摄像头
        //private IOperateWebcam ow_reco; // 展板信息摄像头
        //private IRobotSpeaking rs;      // 机器人说话
        //private ITypeReco tr;           // 展板类型识别
        private IRobotGoSV rgsv;        // 路径控制信息
        private ISerialComm scomm;       // 串口操作

        public GuidingRobotForm()
        {
            InitializeComponent();
            //scomm = new SerialComm(); //初始化串口

            ow_path = new DirectShow(0, videoBoxPath);
            //ow_reco = new DirectShow(0,videoBoxReco);
            ow_path.Start();
            //ow_reco.Start();
        }

        private void GuidingRobotForm_Load(object sender, EventArgs e)
        {
            //ow_path = new VideoForWindows(videoBoxPath.Handle,videoBoxPath.Width,videoBoxPath.Height);
            //ow_reco = new DirectShow(1, videoBoxReco);
            //ow_path.Start();
            //ow_reco.Start();
            //rs = new RobotSpeaking(Application.StartupPath + @"\展板文件.txt");
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            timerPath.Interval = 100;
            //timerReco.Interval = 500;
            timerPath.Start();
            //timerReco.Start();
        }

        private void timerPath_Tick(object sender, EventArgs e)
        {
            Bitmap b = ow_path.Grab(Application.StartupPath + @"\path.jpg");
            picBoxPath.Image = b;
            rgsv = new BitmapProcessIRobotSV(b);
            //sbyte v = rgsv.SetRobotVelocity((sbyte)1);
            sbyte s = rgsv.SetRobotGoScale();

            //【发送控制量给机器】
            //byte ss = Convert.ToByte(s);
            Text = s.ToString();
            //byte[] bytesend = { ss };
            //scomm.WritePort(bytesend);

        }

        
        private void timerReco_Tick(object sender, EventArgs e)
        {/*
            Bitmap b = ow_reco.Grab(Application.StartupPath + @"\reco.jpg");
            picBoxReco.Image = b;
            tr = new BitmapProcessITypeReco();
            int T = tr.GetLabelType(Application.StartupPath + @"\reco.jpg");
            string s = "";
            *if(T > 0)
            {
                //【叫停机器人代码】;
                s = rs.Speak(T);
            }*
            Text=T.ToString();
         */
        }
    
    }
}
